import urllib

import requests
import json
import datetime
import sys

import requests
import time
import aes
import base64
import hashlib



if __name__ == "__main__":
    order_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S%C")
    request_obj = {'RESPCODE': '1',
                   'USERPID': '362201198602190014',
                   'OUTERORDERNO': "test" + order_time,
                   'USERNAME': '叶健忠',
                   # 'BANKNAME': '广发银行',
                   'CARDNO': '6222023602067655266',
                   # "CARDNO": "6259931000063918",
                   # "CVN": "843",
                   # "EXPDATE": "1025",
                   # 'CFGPARA': {'merchant_no': '100031'},
                   "USERTEL": "13600452200",
                   "USERIP": "440223198210310511",
                   "OPMONEY": "10000",
                   # "BANKUNION": "102100099996",
                   'ORDERTIME': order_time,
                   # "FEERATE": 30,
                   # "MERNO": "4606509066",
                   # "SMSCODE": "670612",

                   # "TRANDID": "10301171201163126528",
                   # "PAYORDERID": "10301171201163126528"
                   }

    request_obj["CFGPARA"] = {"MERNO": "101711141567284", "KEY": "87f73eaaead955c58ef9abde7fe9dfcb"} # credit
    # request_obj["CFGPARA"] = {"MERNO": "101711301567246", "KEY": "614fc8bf9937bf79eb839863c8f24312"}
    # request_obj["CFGPARA"] = {"MERNO": "101711141567930", "KEY": "50cb3a717f5938ba99a3f6b0cee982d1"} # detbit
    if sys.argv[1] == "order":
        # request_obj["CFGPARA"]= {"MERNO": "101711141567284", "KEY": "87f73eaaead955c58ef9abde7fe9dfcb"}
        url = 'http://127.0.0.1:10020/jieniu/order'
    elif sys.argv[1] == 'sms':
        # request_obj["CFGPARA"] = {"MERNO": "101711141567284", "KEY": "87f73eaaead955c58ef9abde7fe9dfcb"}
        url = 'http://127.0.0.1:10020/jieniu/sms'
        request_obj["PAYORDERID"] = sys.argv[2]
    elif sys.argv[1] == 'sms_check':
        # request_obj["CFGPARA"] = {"MERNO": "101711141567284", "KEY": "87f73eaaead955c58ef9abde7fe9dfcb"}
        url = 'http://127.0.0.1:10020/jieniu/sms_check'
        request_obj["PAYORDERID"] = sys.argv[2]
        request_obj["CODE"] = sys.argv[3]
    elif sys.argv[1] == 'query':
        # request_obj["CFGPARA"] = {"MERNO": "101711141567284", "KEY": "87f73eaaead955c58ef9abde7fe9dfcb"}
        url = 'http://127.0.0.1:10020/jieniu/query'
        request_obj["OUTERORDERNO"] = sys.argv[2]
    elif sys.argv[1] == 'balance':
        # request_obj["CFGPARA"] = {"MERNO": "101711301567246", "KEY": "614fc8bf9937bf79eb839863c8f24312"}
        # request_obj["CFGPARA"] = {"MERNO": "101711141567284", "KEY": "87f73eaaead955c58ef9abde7fe9dfcb"}
        url = 'http://127.0.0.1:10020/jieniu/balance'
    elif sys.argv[1] == "settlemcg":
        # request_obj["CFGPARA"] = {"MERNO": "101711301567246", "KEY": "614fc8bf9937bf79eb839863c8f24312"}
        # request_obj["PAYORDERID"] = sys.argv[2]
        url = 'http://127.0.0.1:10020/jieniu/settlemcg'
        # request_obj["PAYORDERID"] = sys.argv[2]
        # request_obj["OPMONEY"] = sys.argv[3]
    elif sys.argv[1] == 'settlequery':
        # request_obj["CFGPARA"] = {"MERNO": "101711301567246", "KEY": "614fc8bf9937bf79eb839863c8f24312"}
        # request_obj["CFGPARA"] = {"MERNO": "101711141567284", "KEY": "87f73eaaead955c58ef9abde7fe9dfcb"}
        url = 'http://127.0.0.1:10020/jieniu/settlequery'
        request_obj["OUTERORDERNO"] = sys.argv[2]
        # request_obj["PAYORDERID"] = sys.argv[3]
    rsp = requests.post(url, data=json.dumps(request_obj))
    print(rsp.content)